<?php 
if(wp_verify_nonce($_POST['act_update_agent'],'act_update_agent'))
{	
	## update customer
	$params = array();
	$params['name'] = $_POST['update_customerName'];
	$params['address'] = $_POST['update_customerAddress'];
	$params['email'] = $_POST['update_customerEmail'];
	$params['tel'] = $_POST['update_customerTel'];
	$params['fax'] = $_POST['update_customerFax'];
	
	$customerID = $_POST['update_customerID'];				
	db_update_customer($customerID,$params);
	
	## update company	
	$paramss = array();
	$paramss['companyname'] = $_POST['update_companyName'];
	$paramss['companyaddress'] = $_POST['update_companyAddress'];
	$paramss['companyemail'] = $_POST['update_companyEmail'];
	$paramss['companytel'] = $_POST['update_companyTel'];
	$paramss['companyfax'] = $_POST['update_companyFax'];
	
	$companyID = $_POST['update_companyID'];		
	db_update_company($companyID,$paramss);
}
$agentID = $_GET['agent'];
$cusID   = $_GET['cus'];

$customers = db_select_data_by_int("customers", "ID", $cusID);
$companys = db_select_data_by_int("agents", "ID", $agentID);

?>
<form action="" method="post">
<div class="view-booking-detail">
	<h1>Agent Company Infomation</h1>
	<table>
		<tr>
			<td class="booked-title">Company Name</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_companyName" value="<?php echo $companys[0]->companyName;?>">
			<input type="hidden" name="update_companyID" value="<?php echo $companys[0]->ID;?>">
			<input type="hidden" name="update_customerID" value="<?php echo $customers[0]->ID;?>">
			</span></td>
			
			<td class="booked-title">Company Address</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_companyAddress" value="<?php echo $companys[0]->companyAddress;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Company Email</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_companyEmail" value="<?php echo $companys[0]->companyEmail;?>">
			</span></td>
			
			<td class="booked-title">Company Phone</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_companyTel" value="<?php echo $companys[0]->companyPhone;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Company Fax</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_companyFax" value="<?php echo $companys[0]->companyFax;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Company Comment</td>
			<td class="booked-item"><span><?php echo $companys[0]->companyComment;?></span></td>
		</tr>
		
		<!-- ********************************************************************** -->
		
		<tr>
			<td class="booked-title" colspan="4"><h2>Customer Infomation</h2></td>
			
		</tr>
		<tr>
			<td class="booked-title">Customer Name</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerName" value="<?php echo $customers[0]->customerName;?>">
			</span></td>
			
			<td class="booked-title">Customer Address</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerAddress" value="<?php echo $customers[0]->customerAddress;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Customer Email</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerEmail" value="<?php echo $customers[0]->customerEmail;?>">
			</span></td>
			
			<td class="booked-title">Customer Phone</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerTel" value="<?php echo $customers[0]->customerPhone;?>">
			</span></td>
		</tr>
		<!-- 
		<tr>
			<td class="booked-title">Customer Fax</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerFax" value="<?php echo $customers[0]->customerFax;?>">
			</span></td>
		</tr>
		 -->
		<tr>
			<td class="booked-title">Customer Comment</td>
			<td class="booked-item"><span><?php echo $customers[0]->customerComment;?></span></td>
		</tr>		
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item">
				<input type="submit" name="update_now_tour" value="Update Now">
				<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=travel-agent-setting">Return</a>
			</td>
		</tr>
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item"></td>
		</tr>
	</table>		
</div>
<?php wp_nonce_field('act_update_agent','act_update_agent');?>
</form>